package com.designpattern.softwaredesignpatternstudy.pattern.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LitchiShell
 * @description: 表示书架的类
 * @create 2022-02-01
 */
public class BookShelf implements Aggregate{

    private List<Book> books;

    private int last = 0;

    public BookShelf(int maxSize) {
        this.books = new ArrayList<>(maxSize);
    }

    public Book getBookAt(int index) {
        return books.get(index);
    }

    public void appendBook(Book book) {
        this.books.add(book);
    }

    public int getLength() {
        return books.size();
    }

    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
